﻿using Inventory.Business.API;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Inventory.Business.DomainObjects;
//using Inventory.DAL;
using System.Linq;
using System;

namespace Inventory.Test
{
    /// <summary>
    ///This is a test class for TransferTransactionTest and is intended
    ///to contain all TransferTransactionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class TransferTransactionTest
    {

        TransferTransaction transaction = new TransferTransaction();
        int? transferId;

       

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for TransferTransaction Constructor
        ///</summary>
        [TestMethod()]
        public void TransferTransactionConstructorTest()
        {
            TransferTransaction target = new TransferTransaction();
            Assert.Inconclusive("TODO: Implement code to verify target");
        }

        /// <summary>
        ///A test for GetById
        ///</summary>
        [TestMethod()]
        public void GetByIdTest()
        {
            if (!transferId.HasValue)
                transferId = 12;

            var transfer = transaction.GetById(transferId.Value);

            Assert.IsNotNull(transfer);
            Assert.AreNotEqual(0, transfer.Items.Count);
        }

        /// <summary>
        ///A test for Receive
        ///</summary>
        [TestMethod()]
        public void ReceiveTest()
        {
            if (!transferId.HasValue)
                transferId = 1;

            var transfer = transaction.GetById(transferId.Value);

            transfer.InManualNumber = "UTest In";
            transfer.ReceivedDate = DateTime.Now;
            Assert.IsTrue(transaction.Receive(transfer));

        }

        /// <summary>
        /// A test for Send
        /// </summary>
        [TestMethod()]
        public void SendTest()
        {
            var transfer = new Transfer()
            {
                CreateDate = DateTime.Now,
                Title = "Transfer Test",
                SendingWarehouse = 52,
                OutManualNumber="UTest OUT",
                RecievingWarehouse = 19
            };

            transfer.Items.Add(new TransferMaterialItem()
            {
                Id = 19102,
                Area = Inventory.Business.DomainObjects.Area.Inventory,
                Quantity = 10,
                Cost = 10
            });

            Assert.IsTrue(transaction.Send(transfer));
            transferId = transfer.Id;
            Assert.IsNotNull(transferId);
        }
            //Uncomplete
            //TransferTransaction target = new TransferTransaction();

            //var inv = new Inventory.DAL.InventoryEntities();
            //var whMaterialSender = inv.WarehouseMaterial.Include("Warehouse.WarehouseStatus").Include("Material")
            //    .Where(wh => wh.Warehouse.WarehouseStatus.ID == 2 && ((wh.InventoryQuantity > 0)())).FirstOrDefault();

            //var whMaterialReceived = inv.WarehouseMaterial.Include("Warehouse.WarehouseStatus").Include("Material")
            //    .Where(wh => wh.Warehouse.WarehouseStatus.ID == 2).LastOrDefault();

            //DomainObjects.Transfer transfer = new DomainObjects.Transfer()
            //{
            //    CreateDate = DateTime.Now,
            //    OutCode = "1",
            //    SendingWarehouse = whMaterialSender.Warehouse.ProjectID,
            //    RecievingWarehouse = whMaterialReceived.Warehouse.ProjectID,
            //    Title = "Test"
            //};

            //transfer.Items.Add(new DomainObjects.TransferMaterialItem()
            //{
            //    ID = whMaterialSender.Material.ID,
            //    Cost = whMaterialSender.AvgCost,
            //    Quantity = whMaterialSender.Material.IsOnsite ? whMaterialSender.OnSiteQuantity : whMaterialSender.InventoryQuantity
            //});

            //bool expected = true;
            //bool actual;

            //actual = target.Send(transfer);
            //Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        

        /// <summary>
        ///A test for TransferMaterialConverter
        ///</summary>
        [TestMethod()]
        public void TransferMaterialConverterTest()
        {
            TransferTransaction target = new TransferTransaction(); // TODO: Initialize to an appropriate value
            DAL.Material material = null; // TODO: Initialize to an appropriate value
            TransferMaterialItem expected = null; // TODO: Initialize to an appropriate value
            TransferMaterialItem actual;
            actual = target.TransferMaterialConverter(material);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        [TestMethod()]
        public void completeScenario()
        {
            SendTest();
            GetByIdTest();
            ReceiveTest();
        }
    }
}
